package com.tjtt.common.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class CopyFileUtil {

	public static void copydirectiory(String sourceFile, String destFile)
			throws IOException {
		try {
			(new File(destFile)).mkdirs();
			File[] file = (new File(sourceFile)).listFiles();
			if (file == null || file.length < 1) {
				System.out.println("原始文件不存在!");
				return;
			}
			for (int i = 0; i < file.length; i++) {
				if (file[i].isFile()) {
					FileInputStream input = new FileInputStream(file[i]);
					String fileName = file[i].getName();
					String postfix = fileName.substring(fileName
							.lastIndexOf("."));
					FileOutputStream output = new FileOutputStream(destFile+File.separator + fileName);
					byte[] b = new byte[1024 * 5];
					int len;
					while ((len = input.read(b)) != -1) {
						output.write(b, 0, len);
					}
					output.flush();
					output.close();
					input.close();

				}

				// 判断是否是文件夹是递归调用

				if (file[i].isDirectory()) {
					copydirectiory(sourceFile + "/"+ file[i].getName()
							,destFile + "/"+ file[i].getName());
				}
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args){
		try {
			CopyFileUtil.copydirectiory("C:\\upload\\20090803\\20090803091710vS0444","c:\\upload\\parabak\\20090803091710vS0444");
			System.out.println("复制完成");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
